//
//  UIView+BBKit.m
//  goodsOwner
//
//  Created by apple on 2019/6/28.
//  Copyright © 2019年 fandecai. All rights reserved.
//

#import "UIView+BBKit.h"

@implementation UIView (BBKit)


- (BBLabelViewModel * (^)(NSInteger tag))addLabel{
//    @weakify(self);
    return ^(NSInteger tag){
//        @strongify(self);
        UILabel * label = [[UILabel alloc] init];
        [self addSubview:label];
        BBLabelViewModel * model = [[BBLabelViewModel alloc] initWithTag:tag andView:label];
        return model;
    };
}

BBKIT_REGIST_VIEW_API(addView, UIView, BBViewModel)
BBKIT_REGIST_VIEW_API(addImageView,UIImageView, BBImageViewModel);

#pragma mark - # 按钮类
BBKIT_REGIST_VIEW_API(addControl,UIControl, BBControllerViewModel);
BBKIT_REGIST_VIEW_API(addTextField,UITextField, BBTextFieldViewModel);
BBKIT_REGIST_VIEW_API(addButton, UIButton, BBUIButtonViewModel);
BBKIT_REGIST_VIEW_API(addSwitch,UISwitch, BBSwichViewModel);

#pragma mark - # 滚动视图类
BBKIT_REGIST_VIEW_API(addScrollView, UIScrollView, BBScrollViewModel);
BBKIT_REGIST_VIEW_API(addTextView,UITextView, BBTextViewModel);


//BBKIT_REGIST_VIEW_API(addTableView,UITableView, BBTableViewModel);
- (BBTableViewModel * (^)(NSInteger tag))addTableView{
    //    @weakify(self);
    return ^(NSInteger tag){
        //        @strongify(self);
        UITableView * tabel = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 100, 100) style:UITableViewStyleGrouped];
        tabel.tableFooterView=[UIView new];
        tabel.estimatedRowHeight = 0;
        tabel.estimatedSectionFooterHeight = 0;
        tabel.estimatedSectionHeaderHeight = 0;
        [self addSubview:tabel];
        BBTableViewModel * model = [[BBTableViewModel alloc] initWithTag:tag andView:tabel];
        return model;
    };
}

/**初始化CollectionView对象*/
- (BBCollectionViewModel * (^)(NSInteger tag))addCollectionView
{
    return ^BBCollectionViewModel* (NSInteger tag) {
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.minimumInteritemSpacing = layout.minimumLineSpacing = 0;
        layout.headerReferenceSize = layout.footerReferenceSize = CGSizeZero;
        layout.sectionInset = UIEdgeInsetsZero;
        UICollectionView *view = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        [self addSubview:view];
        BBCollectionViewModel *chainModel = [[BBCollectionViewModel alloc] initWithTag:tag andView:view];
        return chainModel;
    };
}


@end
